package com.example.mysql.jpa.many_to_many;

import com.example.mysql.jpa.domain.TestData;
import com.example.mysql.jpa.repository.TRepostory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class InsertTstet
{
    @Autowired
    private TRepostory tRepostory;

    @Test
    public void insert()
    {
        List<TestData> list = new ArrayList<>();
        for (int i = 0; i < 100; i++)
        {
            TestData testData = new TestData();
            testData.setId(i);
            testData.setText("text: " + i);
            list.add(testData);
        }
        tRepostory.saveAll(list);
    }

    @Test
    public void update()
    {
        TestData testData1 = new TestData();
        testData1.setId(1);

        TestData testData2 = new TestData();
        testData2.setId(2);
        for (int i = 0; i < 100; i++)
        {
            testData1.setText("xxxxxx:" + i);
            tRepostory.save(testData1);

            testData2.setText("xxxxxx:" + i);
            tRepostory.save(testData2);
        }

    }
}
